home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / util1 / yk211src.lha / Yak_2.11_Src / WBStartup / ARexx.c next >
C/C++ Source or Header  |  1995-10-18  |  2KB  |  97 lines

  1. /*
  2.  *
  3.  * Send ARexx Command
  4.  *
  5.  */
  6.  
  7.  
  8. #include <exec/types.h>
  9. #include <exec/libraries.h>
  10. #include <exec/memory.h>
  11.  
  12. #include <rexx/rxslib.h>
  13. #include <rexx/errors.h>
  14.  
  15. #include <proto/exec.h>
  16. #include <proto/rexxsyslib.h>
  17.  
  18. #include <string.h>
  19.  
  20. #include "Arexx.h"
  21. #include "Requesters.h"
  22. #include "yak_locale_strings.h"
  23.  
  24. struct Library *RexxSysBase;
  25.  
  26.  
  27.  
  28. /* 
  29.  * Send an ARexx command 
  30.  * This function is slightly modified from Stefan Becker's one used in ToolManager
  31.  */
  32. LONG
  33. SendARexxCommand(char *PortName, char *command)
  34. {
  35.     LONG rc=RC_ERROR;
  36.     struct MsgPort *DummyPort;
  37.  
  38.     /* Open ARexx system library */
  39.     if ((RexxSysBase = (struct Library *)OpenLibrary(RXSNAME,0)) &&
  40.         (DummyPort = CreateMsgPort ()))
  41.     {
  42.         struct RexxMsg *rxmsg;
  43.  
  44.         if (rxmsg=CreateRexxMsg(DummyPort,NULL,NULL)) 
  45.         {
  46.             if (rxmsg->rm_Args[0]=CreateArgstring(command,strlen(command))) 
  47.             {
  48.                 struct MsgPort *AREXXPort; /* Port of ARexx resident process */
  49.  
  50.                 /* Init Rexx message */
  51.                 rxmsg->rm_Action=RXCOMM|RXFF_NOIO;
  52.  
  53.  
  54.                 /* Find port and send message */
  55.                 Forbid();
  56.  
  57.                 if (PortName)
  58.                 {
  59.                     AREXXPort=FindPort(PortName);
  60.                 }
  61.                 else
  62.                 {
  63.                     AREXXPort=FindPort("AREXX");
  64.                 }
  65.  
  66.                 if (AREXXPort) 
  67.                 {
  68.                     PutMsg(AREXXPort,(struct Message *) rxmsg);
  69.                 }
  70.                 Permit();
  71.  
  72.                 /* Success? */
  73.                 if (AREXXPort) 
  74.                 {
  75.                     /* Yes, wait on reply and remove it */
  76.                     WaitPort(DummyPort);
  77.                     GetMsg(DummyPort);
  78.  
  79.                     /* Check return code */
  80.                     rc=rxmsg->rm_Result1;
  81.                 }
  82.                 else
  83.                 {
  84.                     PostError(getString(AREXX_port_not_found_ERR), PortName);
  85.                 }
  86.  
  87.                 ClearRexxMsg(rxmsg,1);
  88.             }
  89.             DeleteRexxMsg(rxmsg);
  90.         }
  91.         DeleteMsgPort(DummyPort);
  92.         CloseLibrary(RexxSysBase);
  93.     }
  94.     return(rc);
  95. }
  96.  
  97.